package com.cy.ppj.web.admin.mall;

import com.cy.ppj.model.PageBean;
import com.cy.ppj.model.Result;
import com.cy.ppj.model.ao.mall.BrandRecommendSaveAO;
import com.cy.ppj.model.domian.mall.BrandRecommend;
import com.cy.ppj.model.query.mall.BrandRecommendAdminListQuery;
import com.cy.ppj.model.vo.mall.BrandRecommendAdminDetailVO;
import com.cy.ppj.model.vo.mall.BrandRecommendAdminListVO;
import com.cy.ppj.service.comm.FileService;
import com.cy.ppj.service.mall.BrandRecommendService;
import com.cy.ppj.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 后台-品牌推荐管理
 * @Author tanyilin
 * @Date 2019/9/26 16:16
 */
@RestController
@RequestMapping("/admin/mall/brand/recommend")
@Api(tags = "后台-品牌推荐管理")
public class AdminBrandRecommendController extends BaseController {

    @Autowired
    private BrandRecommendService brandRecommendService;
    @Autowired
    private FileService           fileService;

    @ApiOperation("品牌推荐列表")
    @GetMapping("/list")
    public PageBean<BrandRecommendAdminListVO> getList(BrandRecommendAdminListQuery query) {

        PageBean<BrandRecommendAdminListVO> pageBean = brandRecommendService.getBrandRecommendAdminList(query);
        return pageBean;
    }

    @ApiOperation("品牌推荐详情")
    @GetMapping("/detail")
    public Result<BrandRecommendAdminDetailVO> getDetail(@RequestParam(value = "brandId") Long brandId) {

        BrandRecommendAdminDetailVO detailVO = brandRecommendService.getBrandRecommendAdminDetail(brandId);
        return ok("获取详情成功", detailVO);
    }

    @ApiOperation("新增品牌推荐")
    @PostMapping("/do/add")
    public Result doAddBrandRecommend(@Validated BrandRecommendSaveAO saveAO, BindingResult bindingResult) {

        this.checkError(bindingResult);

        BrandRecommend brandRecommend = new BrandRecommend();
        BeanUtils.copyProperties(saveAO, brandRecommend);
        brandRecommendService.addBrandRecommend(brandRecommend);

        return ok("新增品牌推荐成功");
    }

    @ApiOperation("编辑品牌推荐")
    @PostMapping("/do/edit")
    public Result doEditBrandRecommend(@Validated BrandRecommendSaveAO saveAO, BindingResult bindingResult) {

        this.checkError(bindingResult);

        BrandRecommend brandRecommend = new BrandRecommend();
        BeanUtils.copyProperties(saveAO, brandRecommend);
        brandRecommendService.updateBrandRecommend(brandRecommend);

        return ok("编辑品牌推荐成功");
    }

    @ApiOperation("删除品牌推荐")
    @GetMapping("/delete")
    public Result deleteBrandRecommend(@RequestParam(value = "brandId") Long brandId) {

        BrandRecommend brandRecommend = new BrandRecommend();
        brandRecommend.setBrandId(brandId);
        brandRecommendService.deleteBrandRecommend(brandRecommend);

        return ok();
    }

}
